﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace SetListManager.Models
{

    public class SetList
    {
        /// <summary>
        /// Primary Key
        /// </summary>
        [Key]
        public int SetListID { get; set; }

        /// <summary>
        /// Foreign Key to the band who owns this set.  Cannot be null (every
        /// set list must be associated with a band).
        /// </summary>
        public int BandID { get; set; }

        /// <summary>
        /// Name of Set List
        /// </summary>
        [Required(ErrorMessage = "Set List Name must be specified")]
        [DisplayName("Name")]
        public string Name { get; set; }

        /// <summary>
        /// Date of gig
        /// </summary>
        [DisplayName("Gig Date")]
        [DisplayFormat(DataFormatString="{0:d}")]
        public DateTime GigDate { get; set; } // Time here is ignored

        /// <summary>
        /// Time of gig
        /// </summary>
        [DisplayName("Gig Start Time")]
        public TimeSpan GigTime { get; set; }

        public string GigDateTimeFormatted
        {
            get
            {
                return String.Format("{0:d} {1:g}", GigDate, new DateTime(GigTime.Ticks).ToString("h:mm tt"));
            }
        }


        /// <summary>
        /// Set list duration in minutes/seconds.  This is a calculated field,
        /// used for optimization.
        /// </summary>
        [DisplayName("Set Duration")] // NOTE: display name is "Set Duration" so as to not 
                                      // confuse this field with "Song Duration"
        public MinSec SetDuration { get; set; }

        /// <summary>
        /// A collection of all the set's songs and notes
        /// </summary>
        public virtual ICollection<SetListItem> Items { get; set; }

//        public int MyProperty { get; set; }
    }

    /// <summary>
    /// An item in a set list.  Each item in this table refers to either: 
    /// 1) a song in the set list, or 2) a note for the set list
    /// </summary>
    public class SetListItem
    {
        /// <summary>
        /// Primary Key
        /// </summary>
        [Key]
        public int SetListItemID { get; set; }

        /// <summary>
        /// A foreign key which points to the SetList this item is a part of
        /// </summary>
        public int SetListID { get; set; }

        /// <summary>
        /// The set number this item belongs to: 1, 2 or 3 typically.
        /// </summary>
        [Required]
        [DisplayName("Set Number")]
        public int SetNumber { get; set; }

        /// <summary>
        /// This item's ordering within the set number: 1 is first song in set, 2 is second, etc.
        /// </summary>
        [Required]
        [DisplayName("Song Order")]
        public int SongOrder { get; set; }

        /// <summary>
        /// If item is a song: Pointer to our song.  Can be NULL -- if so, then this
        /// item is a Note.
        /// </summary>
        public Song Song { get; set; }

        /// <summary>
        /// If this item is a note: The note text.  Can be NULL -- if so, then this
        /// item is a Song.
        /// </summary>
        [DataType(DataType.MultilineText)]
        [DisplayName("Note")]
        public string Note { get; set; }

        // public int test { get; set; }

    }

    /// <summary>
    /// The SetListSongModel class encapsulates a set list object along with the collection
    /// of songs in that set list.  Used to optimize our queries and simplify
    /// passing our model to our set list views.
    /// </summary>
    public class SetListSongsModel
    {
        public SetList SetList;
        public IQueryable<SetListItem> SetListItems;
    }


//    /// <summary>
//    /// Encapsulates an archived set list -- all the values are flattened
//    /// in this object, so we can archive the info
//    /// </summary>
//    public class ArchiveSetList : SetList
//    {
//    }


//    /// <summary>
//    /// Encapsulates one song in a set list in an archived state.  All of the values
//    /// from the original set list are copied (e.g. not referenced) here so they persist
//    /// in this state.
//    /// </summary>
//    public class ArchiveSetListSong : SetListSong
//    {
//        public string ArchiveTitle { get; set; }
//        public string ArchiveKey { get; set; }
//        public string ArchiveSoloist { get; set; }
//        public string ArchiveGenre { get; set; }
//        public string ArchiveTempo { get; set; }
//        public MinSec ArchiveDuration { get; set; }
//        public UsageType ArchiveUsage { get; set; }
//        public string ArchiveNote { get; set; }
//    }

}